package com.bms.api.bussiness.news.web;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.bms.common.base.common.bean.Result;
import com.bms.common.base.web.BaseController;
import com.bms.common.bussiness.news.entity.News;
import com.bms.common.bussiness.news.service.INewsService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * 新闻表 前端控制器
 * </p>
 *
 * @author xj
 * @since 2018-08-15
 */
@RestController
@RequestMapping("news")
@Api(value="News-Api",tags="新闻接口")
@CacheConfig(cacheNames = "news",keyGenerator="keyGenerator")
@Cacheable
public class NewsController extends BaseController{

	@Autowired
	private INewsService newsService;
	
	@PostMapping("list")
	@ApiOperation(value = "新闻列表")
	public Result list(@RequestParam(defaultValue = "1",required=false)Integer pageNum,
			  		   @RequestParam(defaultValue = "10",required=false)Integer pageSize){
		return json(newsService.selectPage(new Page<>(pageNum, pageSize), new EntityWrapper<News>().eq("status", 2).orderBy("update_time", false)));
	}
	
	@GetMapping("info/{id}")
	@ApiOperation(value = "新闻详情")
	public Result info(@PathVariable Long id){
		return json(newsService.selectById(id));
	}
	
}

